package com.xiaochang.em.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaochang.em.constants.Constants;
import com.xiaochang.em.entity.Star;
import com.xiaochang.em.exception.ServiceException;
import com.xiaochang.em.mapper.StarMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StarService extends ServiceImpl<StarMapper, Star> {

    @Resource
    private StarMapper starMapper;

    public List<Star> allStar() {
        return starMapper.allStar();
    }

    public PageInfo<Star> queryAllStar(int pageNum, int pageSize) {
        //设置当前页面以及每页显示的记录数
        PageHelper.startPage(pageNum, pageSize);
        //执行查询处理
        List<Star> list = starMapper.allStar();
        //设置PageInfo对象
        PageInfo<Star> result = new PageInfo<>(list);
        return result;
    }

    public Boolean predictStar(Star star){
        return starMapper.save(star);
    }

    public List<Star> queryByClass(String subClass) {
        return starMapper.queryByClass(subClass);
    }

    public PageInfo<Star> queryClassStar(int pageNum, int pageSize, String subClass) {
        //设置当前页面以及每页显示的记录数
        PageHelper.startPage(pageNum, pageSize);
        //执行查询处理
        List<Star> list = starMapper.queryByClass(subClass);
        //设置PageInfo对象
        PageInfo<Star> result = new PageInfo<>(list);
        return result;
    }

    public Star queryById(String obSid) {
        Star star = starMapper.queryById(obSid);
        if(star == null) {
            throw new ServiceException(Constants.CODE_403,"没有该恒星");
        }
        return starMapper.queryById(obSid);
    }

    public Boolean login(Integer id, String obSid) {
        return null;
    }

}
